import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# 设置中文字体和解决负号显示问题
plt.rcParams['font.sans-serif'] = ['Songti SC']
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['font.size'] = 14
# 读取Excel文件
df = pd.read_excel('./data/WindInfo.xls')
# 提取经度(lon)，纬度(lat)
# 东向风速分量(ws * cos(wd)) 和 北向风速分量(ws * sin(wd))
lon = df['lon'].values
lat = df['lat'].values
ws = df['ws'].values  # 风速
wd = df['wd'].values  # 风向（角度）
cities = df['city'].values
# 将风向转换为弧度，并计算U,V分量
wd_rad = np.radians(wd)
u = -ws * np.sin(wd_rad)
v = -ws * np.cos(wd_rad)
# 绘制矢量场图
plt.figure(figsize=(10, 8))
plt.quiver(lon, lat, u, v, ws, cmap='jet')
# 添加颜色条
plt.colorbar(label='风速(m/s)')
plt.scatter(lon, lat, c='black', s=20, label='城市', zorder=5)
for i in range(len(lon)):
    plt.text(lon[i], lat[i], df['city'][i],
             fontsize=10, color='red',
             ha='right', va='bottom')

plt.title('内蒙古主要城市风向示意图')
plt.xlabel('经度')
plt.ylabel('纬度')
plt.savefig('./Figures/QuiverPlot09-11.png', dpi=300)
plt.show()
